#include "ComponentTreeItem.h"
#include <QDebug>

ComponentTreeItem::ComponentTreeItem(ComponentTreeItem* parent)
{
    //parentItem = QSharedPointer<ComponentTreeItem>(parent);
    parentItem = parent;
}
ComponentTreeItem::ComponentTreeItem(const QList<QVariant>& data, ComponentTreeItem *parent)
{
    itemData = data;
    //parentItem = QSharedPointer<ComponentTreeItem>(parent);
    parentItem = parent;
}

ComponentTreeItem::~ComponentTreeItem()
{
    qDeleteAll(childItems);
}

void ComponentTreeItem::appendChildItem(ComponentTreeItem* childItem)
{
    childItems.append(childItem);
}

ComponentTreeItem* ComponentTreeItem::childItem(int row)
{
    return childItems.value(row);
}

void ComponentTreeItem::removeChildItem(ComponentTreeItem* childItem)
{
    childItems.removeAt(
            childItems.indexOf(childItem)
            );
}

int ComponentTreeItem::childCount() const
{
    return childItems.count();
}

int ComponentTreeItem::row() const
{
    if(parentItem)
        return parentItem->childItems.indexOf( const_cast<ComponentTreeItem*>(this) );
    return 0;
}

int ComponentTreeItem::columnCount() const
{
    return itemData.count();
}

QVariant ComponentTreeItem::data(int column) const
{
     return itemData.value(column);
}

ComponentTreeItem* ComponentTreeItem::parent()
{
    //return parentItem.data();
    return parentItem;
}
